#ifndef __STEPPER_H
#define __STEPPER_H

#include <rtdevice.h>
#include <rtthread.h>

enum stepper_dir_t
{
    STEPPER_DIR_CW,
    STEPPER_DIR_CCW
};

enum stepper_en_t
{
    STEPPER_EN_ENABLED,
    STEPPER_EN_DISABLED
};

struct stepper_device_t
{
    uint32_t dir;
    uint32_t en;
    volatile uint32_t motor_lock;

    uint32_t step_pin;
    uint32_t en_pin;
    uint32_t dir_pin;

    uint8_t timer_device_name[10];
    rt_device_t timer_device;
    rt_err_t (*cb)(rt_device_t dev, rt_size_t size);

    uint8_t pwm_device_name[10];
    rt_device_t pwm_device;
    int pwm_channel;
};

extern struct stepper_device_t motor_x;
extern struct stepper_device_t motor_y;
void stepper_port_init();
void stepper_launch(struct stepper_device_t *ins, int32_t speed, uint32_t duration);
void stepper_init(struct stepper_device_t *ins);
void stepper_enable(struct stepper_device_t *ins);
void stepper_disable(struct stepper_device_t *ins);
void stepper_dir_set(struct stepper_device_t *ins, enum stepper_dir_t dir);
void stepper_dir_reverse(struct stepper_device_t *ins);
rt_err_t motor_x_cb(rt_device_t dev, rt_size_t size);
rt_err_t motor_y_cb(rt_device_t dev, rt_size_t size);

#endif